package com.qf.java2201.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.java2201.common.PageVo;
import com.qf.java2201.common.R;
import com.qf.java2201.mapper.NoticeMapper;
import com.qf.java2201.pojo.Notice;
import com.qf.java2201.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author hanhan
 */
@Service("noticeService")
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public PageVo<Notice> getPageData(Map<String, Object> params) {

        String page = (String) params.get("page");
        String limit = (String) params.get("limit");

        //mybatis
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));

        List<Notice> notices = noticeMapper.selectByParams(params);

        PageInfo<Notice> noticePageInfo = new PageInfo<>(notices);

        //把分页数据 封装到PageVo  这个PageVo 符合layui 的列表数据格式
        PageVo<Notice> noticePageVo = new PageVo<>();
        noticePageVo.setData(noticePageInfo.getList());
        noticePageVo.setCode(0);
        noticePageVo.setCount(noticePageInfo.getTotal());
        noticePageVo.setMsg("公告列表数据");
        return noticePageVo;

    }

    @Override
    public int addNotice(Notice notice) {
        return noticeMapper.addNotice(notice);
    }

    @Override
    public int deleteNotice(Integer id) {
        return noticeMapper.deleteNotice(id);
    }

    @Override
    public int updateNotice(Notice notice) {
        return noticeMapper.updateNotice(notice);
    }


    @Override
    public void addNoticeList(List<Notice> notices) {
        //批量添加
        noticeMapper.addNoticeList(notices);

    }

    @Override
    public List<Notice> selectList(Notice notice) {
        return noticeMapper.selectList(notice);
    }


}
